package com.example.demo.huawei;

import java.util.LinkedList;
import java.util.Scanner;

/**
 * 输出好朋友位置
 * 8
 * 123 124 125 121 119 122 126 123
 * 输出：
 * 1 2 6 5 5 6 0 0
 */
public class Main48 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

//        for (int i = 0; i < arr.length; i++) {
//            boolean find = false;
//            for (int j = i + 1; j < arr.length; j++) {
//                if (arr[j] > arr[i]) {
//                    arr[i] = j;
//                    find = true;
//                    break;
//                }
//            }
//            if (!find) {
//                arr[i] = 0;
//            }
//        }
        // 改为栈实现
        int[] f = new int[n];
        LinkedList<Integer> stack = new LinkedList<>();
        stack.push(0);
        for (int i = 1; i < n; i++) {
            while (!stack.isEmpty() && arr[i] > arr[stack.peek()]) {
                f[stack.pop()] = i;
            }
            stack.push(i);
        }

        StringBuilder sb = new StringBuilder();
        for (int i : f) {
            sb.append(i).append(" ");
        }
        System.out.println(sb.toString().trim());
    }
}
